package com.echo.im.client.config.condition;

import com.echo.im.client.config.MessageRouteConfig;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class UserStatusServiceEnabledCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获取配置属性值
        String enabled = context.getEnvironment().getProperty("im.client.user-status-enabled", "true");

        // 检查容器中是否有 MessageRouteConfig 类型的 Bean
        boolean isMessageRouteConfigPresent =
                context.getBeanFactory().getBeanNamesForType(MessageRouteConfig.class).length > 0;

        // 如果配置属性为 true，或者存在 MessageRouteConfig 类型的 Bean，则条件成立
        return Boolean.parseBoolean(enabled) || isMessageRouteConfigPresent;
    }
}
